﻿@inherits BaseComponent

<ul class="kui-app-menu">
    @if (Items != null && Items.Count > 0)
    {
        foreach (var item in Items)
        {
            if (item.Target != "Menu" || !item.Visible)
                continue;

            <li @onclick="e=>OnItemClick(item)" style="width:@(Width)%">
                @if (item.Badge > 0)
                {
                    <Badge Count="item.Badge">
                        <div class="kui-app-menu-icon" style="background-color:@item.Color">
                            <Icon Type="@item.Icon" Theme="outline" />
                        </div>
                    </Badge>
                }
                else
                {
                    <div class="kui-app-menu-icon" style="background-color:@item.Color">
                        <Icon Type="@item.Icon" Theme="outline" />
                    </div>
                }
                <div>@item.Name</div>
            </li>
        }
    }
</ul>

@code {
    private double Width => 100 / Count;

    [Parameter] public int Count { get; set; } = 2;
    [Parameter] public List<MenuInfo> Items { get; set; }

    private void OnItemClick(MenuInfo item)
    {
        if (string.IsNullOrWhiteSpace(item.Url))
            return;

        App?.NavigateTo(item);
    }

}